#include <bits/stdc++.h>
using namespace std;
int n, q, p, z[30];
int main() {
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q >> p;
    for (int i = 1; i <= n; i++) {
        cin >> z[i];
    }
    while (q--) {
        int o, x;
        cin >> o >> x;
        int cnt = 0;
        for (int l = 1; l <= n; l++) {
            for (int r = l; r <= n; r++) {
                for (int y = 0; y < p; y++) {
                    int a = x;
                    int b = y;
                    if (o == 2) swap(a, b);
                    bool ok = true;
                    for (int i = l, j = r; i <= r; i++, j--) {
                        if ((a * z[i] + b) % p != z[j]) {
                            ok = false;
                            break;
                        }
                    }
                    if (ok) cnt++;
                }
            }
        }
        cout << cnt << '\n';
    }
    cout << flush;
    return 0;
}